<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>${title }</title>
    <link rel="stylesheet" href="${basePath}/static/bootstrap/css/bootstrap.css"/>
    <link href="${basePath}/static/css/basic.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/login.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/list.css" rel="stylesheet" type="text/css">
<%--     <link rel="stylesheet" href="${basePath}/static/css/content_leftNav.css"/>
    <link rel="stylesheet" href="${basePath}/static/css/FrontControl.css"/> --%>
    <script  type="text/javascript" src="${basePath}/static/js/jquery.min.js"></script>
	<script  type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${basePath}/static/page/jqPaginator/jqPaginator.js"></script>
	<script  type="text/javascript" src="${basePath}/static/js/util.js"></script>
    <script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
    <link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet" type="text/css">
    
</head>
<body>
<!--头部-->
	<%@include file="/WEB-INF/templates/common/header.jsp"%>
	<!------导航条-->
	<%@include file="/WEB-INF/templates/common/navigation.jsp"%>

<!--内容部分-->
<div class="list_main lay_out" class="clearfix">
    <div class="list_DH">
        <%@include file="/WEB-INF/templates/common/medBorrowNav.jsp"%>
    </div>
    <div class="list_NR">
        <div class="loc">
            <h3 style="margin:0">借阅审批</h3>
        </div>
        <div class="list_con_table">
            <div class="search_table">
                <ul class="clearfix" style="margin-bottom:0;">
				    <li class="Label_1" style="width:9%">姓名：&nbsp;</li>
				    <li class="Label_2" style="width:20%"><input class="input_box" type="text"   name='name' id='name' value='' /></li>
					<li class="Label_1" style="width:9%">身份证号：&nbsp;</li>
				    <li class="Label_2" style="width:20%"><input class="input_box" type="text"   name='' id='idCard' value='' /></li>
                	<li class="Label_1" style="width:9%">出院日期：&nbsp;</li>
                    <li class="Label_4" style="width:32%;text-align:center;">
                    	<input class="input_box" style="width:42%;" type="text"  name='startTime' id='outHospitalStartDate' value='' onFocus="WdatePicker()" />
                    	<span>&nbsp;-&nbsp;</span>
                    	<input class="input_box" type="text" style="width:42%;"  name='endTime' id='outHospitalEndDate' value='' onFocus="WdatePicker()" />
                    </li>
                    <li class="Label_1" style="width:9%">ID号：&nbsp;</li>
				    <li class="Label_2" style="width:20%"><input class="input_box" type="text"   id='mrId' value='' /></li>
					<li class="Label_1" style="width:9%">审核状态：&nbsp;</li>
				    <li class="Label_2" style="width:20%">
				    	 <input type="radio"  name='isCheck' checked="checked" id='' value='1' />未批&nbsp;&nbsp;
    					 <input type="radio"  name='isCheck' id='' value='2' />已批
    					<input type="radio"  name='isCheck' id='' value='3' />拒批	 
    				</li>
                   	<li class="Label_1" style="width:9%">申请日期：&nbsp;</li>
                    <li class="Label_4" style="width:32%;text-align:center;">
                    	<input class="input_box" style="width:42%;" type="text"  name='startTime' id='applyBorrowStartTime' value='' onFocus="WdatePicker()" />
                    	<span>&nbsp;-&nbsp;</span>
                    	<input class="input_box" type="text" style="width:42%;"  name='endTime' id='applyBorrowEndTime' value='' onFocus="WdatePicker()" />
                    </li>
                    <li class="Label_5">
                        <div class="right" style="text-align:right">
                            <a onclick="queryQua(1,10)">查询</a>
                         	<!-- <a href="javascript:exportBorrowApproveToExcel()">导出</a> -->
                        </div>
                    </li>
                  
                </ul>
            </div> 
            <input type="hidden" value="0" id="totalCountHidden"/>
            <input type="hidden" value="0" id="pageNoHidden"/>
            <!-- 用于批量审批时判断选择的是否是未审批的 -->
            <input type="hidden" id="isApprove" value="">
             <table class="Search_tableList" cellpadding="0" cellspacing="0">
              <!--  <tr><td colspan="7" class="tdLabel_6"><a onclick="batchApprove()">批量批准</a>&nbsp<a onclick="batchReject()">批量拒批</a></td></tr> -->
              <!--  <li style="list-style:none"; class="Label_5">
                        <div class="right" style="text-align:left">
                            <a id="Add" onclick="approveBatch(2)">批量批准</a>
                            <a id="Add" onclick="approveBatch(3)">批量拒批</a>
                        </div>
                </li> -->
                <tr>
                	
             		<!-- <td class="tdLabel_4"><input type="checkbox" onclick="checkAll(this)"></td> 
                     -->
                    <td class="tdLabel_4">ID号</td>
                    <td class="tdLabel_4">姓名</td>
                    <td class="tdLabel_4">证件号码</td>
                    <td class="tdLabel_4">出院科室</td>
                     <td class="tdLabel_4">申请时间</td>
                      <td class="tdLabel_4">申请人</td>
                    <td class="tdLabel_4" style="width:15%">操作</td>
                </tr>
                <tr id="loading" style="height:50px;display:none">
	                 <td colspan="7" align="center" ><img src="${basePath}/static/layer/skin/default/loading-2.gif"></td>
	            </tr>
                <tbody id="tbody">
                
                </tbody>
            </table>
        </div>
      <div class="pageList">
            <ul class="pagination clearfix" id="page_plus"></ul>
            <div class="pagination">
                <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
            </div>
        </div> 
    </div>
</div>
<!------页脚部分--------->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>

<!--JS部分-->
<script type="text/javascript">
	function queryQua(pageNo,pageSize){
		
		var name=$("#name").val();
		var idCard=$("#idCard").val();
		var outHospitalStartDate=$("#outHospitalStartDate").val();
		var outHospitalEndDate=$("#outHospitalEndDate").val();
		var mrId=$("#mrId").val();
		var applyBorrowStartTime=$("#applyBorrowStartTime").val();
		var applyBorrowEndTime=$("#applyBorrowEndTime").val();
		var status=$("input[name='isCheck']:checked").val();;
		//alert(name+"--"+idCard+"--"+outHospitalStartDate+"-"+outHospitalEndDate+"--"+mrId+"--"+applyBorrowStartTime+"--"+applyBorrowEndTime+"--"+status);
		

		//jQuery.support.cors = true;
		$.ajax({
			type:"post",
			url:"${basePath}/borrow/selectApplyBorrowByKeywords",
			data:{checkStatus:status,mrId:mrId,applyBorrowStartTime:applyBorrowStartTime,applyBorrowEndTime:applyBorrowEndTime,idCard:idCard,outHospitalStartDate:outHospitalStartDate,outHospitalEndDate:outHospitalEndDate,name:name,pageNo:pageNo,pageSize:pageSize},
			beforeSend:function(){
				$("#tbody").html("");
				$("#loading").show();
			},
			success:function(data){

				$("#loading").hide();
				
				if(data.success){
					//$("#isApprove").val(data.data.borrowQuery.status);
					var hospitalizationNotes=data.data.borrowRecordList;
					
					if(hospitalizationNotes!=null && hospitalizationNotes.length!=0){
						var totalCounts=data.data.totalCount;
						$("#totalCountHidden").val(totalCounts);
    					$("#pageNoHidden").val(pageNo);

						var html="";
						for(var i=0;i<hospitalizationNotes.length;i++){
							var hospitalizationNote=hospitalizationNotes[i];
							html+=" <tr>"+
								/*   "      <td class='tdLabel_5'><input type='checkbox' name='checkOne'  value="+hospitalizationNote.bcrId+"></td>"+ */
					              "      <td class='tdLabel_5'>"+hospitalizationNote.mrId+"</td>"+
					              "      <td class='tdLabel_5'>"+hospitalizationNote.NAME+"</td>"+
					              "      <td class='tdLabel_5'>"+hospitalizationNote.idCard+"</td>"+
					              "      <td class='tdLabel_5'>"+hospitalizationNote.outOfficeName+"</td>"+     

					              "      <td class='tdLabel_5'>"+hospitalizationNote.borrowTime+"</td>"+
					              "      <td class='tdLabel_5'>"+hospitalizationNote.borrowMan+"</td>";			            
					              if(status==1){
					              html+= "<td class='tdLabel_5' style='width:280px'><a class='int' onlyId='"+hospitalizationNote.onlyId+"' firstGuid='"+hospitalizationNote.firstGuid+"'  bcrId='"+hospitalizationNote.borrowFunctionId+"' status='2' onclick='borrow(this)'>批准</a>&nbsp;&nbsp;<a class='int' bcrId='"+hospitalizationNote.borrowFunctionId+"'  onlyId='"+hospitalizationNote.onlyId+"' firstGuid='"+hospitalizationNote.firstGuid+"'  bcrId='"+hospitalizationNote.borrowFunctionId+"' status='3' onclick='borrow(this)'>拒批</a></td></tr>";
					             }else if(status==2){
					              html+= "      <td class='tdLabel_5' style='width:280px'><a >已批准</a></td></tr>";
					             }else if(status==3){
					              html+= "      <td class='tdLabel_5' style='width:280px'><a >已拒绝</a></td></tr>";
					             }
						}
						
						$("#tbody").html(html);
						page(pageNo,totalCounts,pageSize);

					}else{
						layer.alert("查询的数据为空！",{icon:5});
						$("#tbody").html("");
		                $("#currentPage").html("0/0");
						$("#totalPage").html("0");
						$("#page_plus").html("");

					}

				}else{
					layer.alert(data.msg,{icon:5});
					$("#tbody").html("");
	                $("#currentPage").html("0/0");
					$("#totalPage").html("0");
					$("#page_plus").html("");
				}
	
			}
		})
		
	}
	
	 function page(currentPage,totalCounts,pageSize){

	    	//var totalCounts = 1000;
	        //var pageSize = 1;
	        if(pageSize==null || pageSize=="" || pageSize==0){
	        	pageSize = 10;
	        	alert("size==null \t"+pageSize);
	        }
	        var visiblePages = 10;
	        //var currentPage = 1;
	        /* var totalPages = totalCounts%pageSize==0?(totalCounts/pageSize):(totalCounts/pageSize+1); */
	        var totalPages = Math.ceil(totalCounts/pageSize);
	        $('#page_plus').jqPaginator({

	            totalCounts: totalCounts,
	            pageSize:pageSize,
	            visiblePages: visiblePages,
	            currentPage: currentPage,

	            first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
	            prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
	            next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
	            last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
	            page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
	            onPageChange: function (num,type) {
	            	 if(type !='init'){
	                 
	            		 queryQua(num,pageSize);
	                 }
	            	
	                $("#totalPage").html(totalCounts);
	                $("#currentPage").html(num+"/"+totalPages);
	            }
	        });

	    }
	 
	 	//更新病案借阅状态
		function borrow(obj){
			var bcrId=$(obj).attr("bcrId");
			var status=$(obj).attr("status");
			var onlyId = $(obj).attr("onlyId");
			var firstGuid = $(obj).attr("firstGuid");
			
			$.ajax({
				type:"post",
				url:"${basePath}/borrow/updateApplyStatus",
				data:{id:bcrId,checkStatus:status, onlyId:onlyId, firstGuid:firstGuid},
				success:function(data){
					if(data.success){
						if(status==2){
							$(obj).parents("td").html("批准");
							layer.alert("审批成功",{icon:1});
						}else{
							$(obj).parents("td").html("拒绝");
							layer.alert("申请已拒绝!",{icon:5});
						}
					/* 	$(obj).parents("td").html("slow",function(){
							$(this).remove();
						}); */
						
					/* 	var totalCounts=$("#totalCountHidden").val();
    					var pageNo=$("#pageNoHidden").val();
    					var total=totalCounts-1; */
    					
    				/* 	$("#totalCountHidden").val(total);
    					if(total>0){
    						page(parseInt(pageNo),parseInt(total),0);
    					}else{
    						$("#totalPage").html(0);
    			            $("#currentPage").html(0+"/"+0);
    			            $('#page_plus').html("");
    					} */
					}else{
						layer.alert("审批失败!",{icon:5});
					}
					
					
				}
			})
			
		}
	
		
		function approveBatch (type){
			
			var isCheck = $("#isApprove").val();
			if(isCheck==1){
				var bcrIds = getFormVals("checkOne");
				
				if(bcrIds!=""){
					var confirmMsg = "确定批量审批吗？";
					if(type==2){
						 confirmMsg = "确定要全部批准吗？";
					}else{
						confirmMsg = "确定要全部拒绝吗？";
					}
					
				   layer.confirm(confirmMsg, {
						  btn: ['确定','取消'] //按钮
						}, function(){
							$.ajax({
								type:"post",
								url:"${basePath}/borrow/updateApplyStatusBacth",
								data:{checkStatus:type,ids:bcrIds},
								success:function(data){
									if(data!=null){
										if(data.success){
											layer.alert("批量审批成功",{icon:1});
											var objs = getFormObjs("checkOne");
											for(var i=0;i<objs.length;i++){
												objs[i].parents("tr").fadeOut("slow",function(){
													$(this).remove();
												});
											}
											var totalCounts=$("#totalCountHidden").val();
					    					var pageNo=$("#pageNoHidden").val();
					    					var total=totalCounts-objs.length;
					    					
					    					$("#totalCountHidden").val(total);
					    					if(total>0){
					    						page(parseInt(pageNo),parseInt(total),0);
					    					}else{
					    						$("#totalPage").html(0);
					    			            $("#currentPage").html(0+"/"+0);
					    			            $('#page_plus').html("");
					    					}
										}else{
											layer.alert("批量申批失败!",{icon:5});
										}
										
									}else{
										layer.alert("批量审批失败",{icon:5});
									}
										
								}
							});
						}, function(){
						   layer.close()
						});	
					
					/*  if(confirm(confirmMsg)){
						 $.ajax({
								type:"post",
								url:"${basePath}/borrow/updateApplyStatusBacth",
								data:{checkStatus:type,ids:bcrIds},
								success:function(data){
									if(data!=null){
										if(data.success){
											layer.alert("批量审批成功");
											var objs = getFormObjs("checkOne");
											for(var i=0;i<objs.length;i++){
												objs[i].parents("tr").fadeOut("slow",function(){
													$(this).remove();
												});
											}
											var totalCounts=$("#totalCountHidden").val();
					    					var pageNo=$("#pageNoHidden").val();
					    					var total=totalCounts-objs.length;
					    					
					    					$("#totalCountHidden").val(total);
					    					if(total>0){
					    						page(parseInt(pageNo),parseInt(total),0);
					    					}else{
					    						$("#totalPage").html(0);
					    			            $("#currentPage").html(0+"/"+0);
					    			            $('#page_plus').html("");
					    					}
										}else{
											layer.alert("批量申批失败!",{icon:5});
										}
										
									}else{
										layer.alert("批量审批失败",{icon:5});
									}
										
								}
							});
					 } */
					
				}else{
					layer.alert("请至少选择一条记录",{icon:7});
				}
			}else{
				layer.alert("请选择未审批的记录",{icon:7});
			}
			
		}
</script>

</body>
</html>